/**
 * # # THIS FILE IS PART OF ripap PROJECT
 * # #
 * # StrUtils.java - 字符串处理类
 * #
 * # THIS PROGRAM IS OPENSOURCE SOFTWARE, IS LICENSED UNDER BSD
 * # YOU SHOULD HAVE RECEIVED A COPY OF WTFPL LICENSE
 * #
 * # Copyright (c) 2018 Ting Fan
 */
package com.cloudkinto.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program     : ripap
 * @description : 字符串处理类
 * @author      : Ting Fan
 * @company     : 苏州
 * @create      : 2019-05-21 11:00
 **/
public class StrUtils {

    public static int getSubCount(String str, String key) {
        int count = 0;
        int index = 0;
        while ((index = str.indexOf(key, index)) != -1) {
            index = index + key.length();

            count++;
        }
        return count;
    }

    public static String handlerListToStrSplitBySemicolon(List<String> stringList) {
        String result = "";
        if (stringList == null) {
            return result;
        }
        for (int i = 0; i < stringList.size(); i++) {
            if (i == stringList.size() - 1) {
                result = result + stringList.get(i);
            } else {
                result = result + stringList.get(i) + ";";
            }
        }
        return result;
    }

    public static List<String> handlerStrToListSplitBySemicolon(String str) {
        List<String> result = new ArrayList<>();
        if (StringUtils.isNotBlank(str)) {
            String[] strArray = str.split(";");
            result = Arrays.asList(strArray);
        }
        return result;
    }

    public static String handlerListToStrSplitByComma(List<String> stringList) {
        String result = "";
        for (int i = 0; i < stringList.size(); i++) {
            if (i == stringList.size() - 1) {
                result = result + stringList.get(i);
            } else {
                result = result + stringList.get(i) + ",";
            }
        }
        return result;
    }


    public static void main(String[] args) {
        String str = "◎";
        String strAll = "dsladshbfjks◎h;dfashfsd;◎jodshflgasd◎";
        System.out.println(getSubCount(strAll, str));

    }

}
